﻿using EFSQLiteOneToManay.ModelDTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFSQLiteOneToManay
{
   public class GenerateTempData
    {
        private InspItemRecordDTO GetDefaultItemDTO(int i = 1)
        {
            var dto = new InspItemRecordDTO
            {
                Brightness = 200,
                ExproseTime = 1000,
                InspedImg = new System.Drawing.Bitmap(1, 1),
                ItemIndex = -3,
                ItemMsg = "Test",
                ItemName = "测试项",
                ItemResult = false,
                ErrCol = new List<int> { i, i + 2, i + 3, i + 4, i + 5 },
                ErrDiff = new List<int> { i, i + 2, i + 3, i + 4, i + 5 },
                ErrRow = new List<int> { i, i + 2, i + 3, i + 4, i + 5 },
                ErrType = new List<int> { i, i + 2, i + 3, i + 4, i + 5 },
                ErrValue = new List<int> { i, i + 2, i + 3, i + 4, i + 5 }
            };
            return dto;
        }
        private InspGroupRecordDTO GetDefaultGroupDTO(string gname)
        {
            var dto = new InspGroupRecordDTO
            {
                GroupName = gname,
                Items = new List<InspItemRecordDTO> {
                    GetDefaultItemDTO(1),
                    GetDefaultItemDTO(3),
                    GetDefaultItemDTO(4),
                    GetDefaultItemDTO(5),
                    GetDefaultItemDTO(6),
                    GetDefaultItemDTO(7),
                    GetDefaultItemDTO(8),
                    GetDefaultItemDTO(11),
                }
            };
            dto.GroupResult = dto.Items.All(x => x.ItemResult);
            var types = new List<int>();
            dto.Items.ForEach(x => types.AddRange(x.ErrType.Distinct()));
            foreach (var s in types.Distinct())
                dto.ErrorType += s;
            return dto;
        }
        public InspRecordDTO GetDefaultRecordDTO(string pannelid)
        {
            var dto = new InspRecordDTO
            {
                PannelID = pannelid,
                BatchID = "批次1",
                Duaration = 20,
                EndTime = DateTime.Now,
                EquipID = "API",
                LineNO = "NO1",
                ModelID = "0194",
                OperatorID = "Operator1",
                StartTime = DateTime.Now.AddSeconds(23),
            };
            dto.Groups = new List<InspGroupRecordDTO> { GetDefaultGroupDTO("Camera1"), GetDefaultGroupDTO("Camera2"), GetDefaultGroupDTO("Camera3") };
            dto.Groups.ForEach(x => dto.ErrCode = string.Format("{0},{1}", dto.ErrCode, x.ErrorType));
            return dto;
        }
    }
}
